package com.framework.controller.newcontroller;

import com.framework.entity.ter.TerTerminalType;
import com.framework.exception.util.RespResult;
import com.framework.service.TerminalInfoService;
import com.framework.service.TerminalTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 功能描述: 终端信息控制器
 *
 * @author ck
 * @date 2018/9/11 15:12
 */
@RestController
@Api(value="终端信息模块",tags={"终端信息模块"})
@RequestMapping(value = "new/terminal")
public class NewTerminalController {

	@Autowired
	private TerminalInfoService terminalInfoService;
	@Autowired
	private TerminalTypeService terminalTypeService;


	/**
	 * 机具归属查询
	 * @param token 当前登录人token
	 * @param snList 机具sn号
	 * @return
	 */
	@GetMapping("user/queryTerminalOwner")
	@ApiOperation("机具归属查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登陆人token",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="snList",value="sn 数组",dataType="string[]", paramType = "query",required = true),
	})
	public RespResult queryTerminalOwner(String token,String[] snList) {
		List<Map<String,Object>> list = terminalInfoService.queryTerminalOwner(token,snList);
		return RespResult.ok().put("list",list);
	}




	/**
	 * 根据token查询机具类型list
	 * @param token 登录人token
	 * @return
	 */
	@GetMapping("user/queryTerminalTypeList")
	@ApiOperation("根据token查询机具类型")
	public RespResult queryTerminalTypeList(String token) {
		List<TerTerminalType> list = terminalTypeService.queryTerminalTypeByTokenList(token);
		return RespResult.ok().put("typeList",list);
	}



	/**
	 *根据token查询机具型号列表
	 * @param token
	 * @return
	 */
	@GetMapping("user/queryTerminalModelList")
	@ApiOperation("根据token查询机具型号列表")
	@ApiImplicitParam(name="token",value="接收人代理商id",dataType="int", paramType = "query",required = true)
	public RespResult queryTerminalModelList(String token) {
		List<Map<String,Object>> list = terminalTypeService.queryTypeAndModel(token);
		return RespResult.ok().put("modelList",list);
	}


	/**
	 *  终端列表查询 设备管理
	 * @param token
	 * @param startSn
	 * @param endSn
	 * @param terminalType
	 * @param isActivation
	 * @param type
	 * @return
	 */
	@GetMapping("user/queryTerminalListByToken")
	@ApiOperation("终端列表查询 设备管理")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="接收人代理商id",dataType="int", paramType = "query",required = true),
			@ApiImplicitParam(name="startSn",value="开始终端号",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="endSn",value="结束终端号",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="terminalType",value="终端型号",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="isActivation",value="1：未激活 2：已激活 ",dataType="int", paramType = "query"),
			@ApiImplicitParam(name="type",value="1：全部 2：划入 3：划出",dataType="int", paramType = "query"),
	})
	public RespResult queryTerminalListByToken(String token,String startSn,String endSn,Integer terminalType,Integer isActivation,Integer type) {
		Map<String,Object> map= terminalInfoService.queryTerminalListByToken(token,startSn,endSn,terminalType,isActivation,type);
		return RespResult.ok().put("data",map);
	}


	/**
	 * 查询单个sn的流水信息
	 * @param token
	 * @param sn
	 * @return
	 */
	@GetMapping("user/queryFlowInfoBySn")
	@ApiOperation("查询单个sn的流水信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="接收人代理商id",dataType="int", paramType = "query",required = true),
			@ApiImplicitParam(name="sn",value="终端号",dataType="string", paramType = "query"),
	})
	public RespResult queryFlowInfoBySn(String token,String sn) {
		Map<String,Object> map= terminalInfoService.queryFlowInfoBySn(token,sn);
		return RespResult.ok().put("data",map);
	}



}
